<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>申领单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <!--{include file='comm/comm_pic.tpl'}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>

</head>
<body>

<style>
    .imageSites{
        position: absolute;left:275px;top:-1px;
    }
</style>
<div class="container">
    
    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table style="width:100%;">
                            <tbody>
                                <tr>
                                    <td>
                                        <span>
                                             创建日期：
                                            <input class="form-control w150" id="startDate" name="startDate" value="" readonly="readonly" type="text" />
                                            ～
                                            <input class="form-control w150" id="endDate" name="endDate" value="" readonly="readonly" type="text" />
                                        </span>

                                        <span>
                                            客户名称：
                                            <input type="text" class="form-control w150" id="customer_name" name="customer_name" />
                                        </span>

                                        <span>
                                            申领人：
                                            <select class="form-control w150" id="userID" name="apply_user_id">
                                                <option value="">请选择</option>
                                            </select>
                                        </span>
                                        <span>
                                            申请状态：
                                            <select class="form-control w150" id="status" name="status">
                                                <option value="">请选择</option>
                                                <option value="1">申请中</option>
                                                <option value="2">已审核</option>
                                                <option value="3">已发卡</option>
                                            </select>
                                        </span>
                                        <span>
                                            开票状态：
                                            <select class="form-control w150" id="invoice_status" name="invoice_status">
                                                <option value="">请选择</option>
                                                <option value="0">未开票</option>
                                                <option value="1">部分开票</option>
                                                <option value="2">全部开票</option>
                                            </select>
                                        </span>
                                         <span>
                                            回款状态：
                                            <select class="form-control w150" id="returned_money_status" name="returned_money_status">
                                                <option value="">请选择</option>
                                                <option value="0">未回款</option>
                                                <option value="1">部分回款</option>
                                                <option value="2">全部回款</option>
                                            </select>
                                        </span>
                                        <span>
                                            开票申请：
                                            <select class="form-control w150" id="statusKp" name="statusKp">
                                                <option value="">请选择</option>
                                                <option value="1">是</option>
                                                <option value="2">否</option>
                                            </select>
                                        </span>
                                        <span>
                                            部 门：
                                        </span>
                                        <span style="vertical-align: middle">
                                            <div class="search_option">
                                                <div class="search_option_drop" >
                                                    <span id="searchOptions" style="position: relative;">
                                                        请选择
                                                    <font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                                                    </span>
                                                </div>

                                                <ul class="search_option_panel"  id="searchPanels" style="display: none;z-index: 100;">
                                                    <li class="childSelectImg" departmentID="" style="margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >请选择</li>
                                                    <!--{$department_select_html}-->
                                                </ul>

                                                <input type="hidden" value="0" id="hdnSearchTypes" name="hdnSearchType">
                                                <input type="hidden" value="" id="search_departmentID" name="search_departmentID">
                                                <!--<input type="hidden" value="" id="departmentName" name="departmentName">-->
                                            </div>
                                        </span>
                                        <span>
                                            申请编号：<input type="text" value="" name="apply_id" id="apply_id" class="form-control w150">
                                        </span>
                                        <span>
                                            发票编号：<input type="text" value="" name="invoice_no" id="invoice_no" class="form-control w150">
                                        </span>
                                        <span><input type="button" value="查询" id="searchBtn" class="btn btn-primary" onclick="cardApplyList.search();" /></span>
                                        <span><input type="button" value="重置" id="clearBtn" class="btn btn-warning" onclick="cardApplyList.clearUp();" /></span>
                                    </td>
                                </tr>

                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

            <form name="export_from" id="export_from" method="post" action="/quanliadmin/app/company/card.pscript?operFlg=4">
                <input type="hidden" name="card_id" id="cardId" value="">
            </form>

        </div>


</div>

<div id="pop" style="display: none;">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">申领单信息</h3>
        </div>
        <div class="panel-body">
            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="get_card_type">
                    <span class="red">*</span>
                    领卡方式：
                </label>
                <div class="col-sm-10">
                    <select class="form-control w150" id="get_card_type" name="get_card_type">
                        <option value="1">个人</option>
                        <option value="2">公司</option>
                    </select>
                    <input type="hidden" name="apply_id" id="apply_id" value="">
                </div>
            </div>

            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="customer_name">
                    <span class="red">*</span>
                    客户名称：
                </label>
                <div class="col-sm-10">
                    <input type="text" class="form-control w150 fl" placeholder="请输入客户名称"  id="customerName" name="customer_name" value="" readonly="readonly" style="margin-bottom: 6px;"/>
                </div>
            </div>

            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="apply_date">
                    <span class="red">*</span>
                    申领日期：
                </label>
                <div class="col-sm-10">
                    <input type="text" class="form-control w150" placeholder="点击选择申领日期"  id="apply_date" name="apply_date" readonly="readonly" value="" style="margin-bottom: 6px;"/>
                </div>
            </div>

            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="linkman">
                    联系人：
                </label>
                <div class="col-sm-10">
                    <input type="text" class="form-control w150" placeholder="请输入联系人"  id="linkman" name="linkman" value="" style="margin-bottom: 6px;"/>
                </div>
            </div>

            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="contact_way">
                    联系方式：
                </label>
                <div class="col-sm-10">
                    <input type="text" class="form-control w150" placeholder="请输入联系方式"  id="contact_way" name="contact_way" value="" style="margin-bottom: 6px;"/>
                </div>
            </div>

            <div class="form-group" style="margin-bottom: 40px;">
                <label class="col-sm-2 control-label" for="save_remark">
                    备注：
                </label>
                <div class="col-sm-10">
                    <textarea id="remark" class="form-control w300" rows="3" name="remark" style="margin-bottom: 6px;" placeholder="请输入备注"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">现金卡信息</h3>
        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover">
                <thead>
                <tr style="line-height: 45px;">
                    <th width="12%" style="text-align:center;">面额</th>
                    <th width="12%" style="text-align:center;">规格</th>
                    <th width="12%" style="text-align:center;">数量</th>
                    <th width="12%" style="text-align:center;">折扣率</th>
                    <th width="12%" style="text-align:center;">折后价</th>
                    <th width="12%" style="text-align:center;">代金卡类型</th>
                    <th width="12%" style="text-align:center;">备注</th>
                </tr>
                </thead>
                <tbody id="add_tr">

                </tbody>
            </table>
        </div>
    </div>
    <!--add by  dongleixin 显示发卡日志信息 start-->
    <div class="panel panel-default" id="apply" style="display: none;">
        <div class="panel-heading">
            <h3 class="panel-title">发卡日志</h3>
        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover">
                <thead>
                <tr style="line-height: 45px;">
                    <th width="12%" style="text-align:center;">起始卡号</th>
                    <th width="12%" style="text-align:center;">结束卡号</th>
                    <th width="12%" style="text-align:center;">发卡张数</th>
                    <th width="12%" style="text-align:center;">发卡面额</th>
                    <th width="12%" style="text-align:center;">激活时间</th>
                    <th width="12%" style="text-align:center;">激活人</th>
                </tr>
                </thead>
                <tbody id="add_str">

                </tbody>
            </table>
        </div>
    </div>
    <!--add by  dongleixin 显示发卡日志信息 start-->
</div>

<script>

$("#flex").flexigrid({
    url:"/invokingAjax-backend/company/cardApply.ajax?operFlg=1",
    dataType: "json",
    colModel : [
        {display: "操作", width : 200, align:"center"},
        {display: "申请编号", name : "apply_id", sortable : true,width : 120,align:"left"},
        {display: "申请日期", width : 100,align:"left"},
        {display: "客户类型", width : 70,align:"left"},
        {display: "客户名称", width : 100,align:"left"},
        {display: "联系人", width : 80,align:"center"},
        {display: "联系方式", width : 140,align:"center"},
        {display: "部门", width : 150,align:"left"},
        {display: "回款状态", width : 70,align:"left"},
        {display: "是否开票申请", width : 100,align:"left"},
        {display: "申领现金卡数量", width : 100,align:"left"},
        {display: "申领人", width : 80,align:"center"},
        {display: "申请现金卡金额", width : 120,align:"left"},
        {display: "回款方式", width : 200,align:"left"},
        {display: "发卡时间", width : 200,align:"left"},
        {display: "申请状态", width : 100,align:"left"},
        {display: "开票状态", width : 100,align:"left"},
	{display: "备注", width : 300,align:"left"}

    ],
    buttons : [
        {name: "添加", bclass: "add", onpress : "cardApplyList.add.open"}
    ],
    sortname: "apply_id",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});
$('#startDate').datetimepicker();
$('#endDate').datetimepicker();

var cardApplyList ={

    card_id:'',//现金卡生产单ID

    //头部 按条件查询
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({newp: 1,params: dt}).flexReload();
    },


    //重置
    clearUp:function() {
        document.getElementById('search_form').reset();
        this.search();

    },

    //添加大客户信息
    add:{
        open:function(){
            window.open("/quanliadmin/app/company/cardApply.pscript?operFlg=2");
        }
    },

    //编辑大客户信息
    edit: function(apply_id) {

        window.open("/quanliadmin/app/company/cardApply.pscript?operFlg=2&apply_id=" + apply_id);

    },

    //编辑大客户信息
    look: function(apply_id,sudit) {
        if(sudit=="OK"){
            E.popup.open({
                id: 'pop',
                title: '申领详情',
                css: 'width: 1000px;',
                btnName:'审核',
                btnCall:"cardApplyList.audit('"+apply_id+"');"
            });

        }else{
            E.popup.open({
                id: 'pop',
                title: '申领详情',
                css: 'width: 1000px;'
            });
        }

        E.ajax_get({
            url:  "/invokingAjax-backend/company/cardApply.ajax?operFlg=13&apply_id=" + apply_id,
            //data: {},
            call: function( o ) {

                if (o.code == 200) {
                    $('#get_card_type').val(o.data.get_card_type);
                    $('#customerName').val(o.data.customer_name);
                    $('#apply_date').val(o.data.apply_date);
                    $('#linkman').val(o.data.linkman);
                    $('#contact_way').val(o.data.contact_way);
                    $('#remark').val(o.data.remark);
                    var html = '';
                    $.each(o.data.detail,function(k,v){

                        html += '<tr id="card_line_' + this.index + '">';
                        html += '<td>' + v.face_value + '</td>';
                        html += '<td>' + v.card_spec + '</td>';
                        html += '<td>' + v.card_num + '</td>';
                        html += '<td>' + v.card_discount + '</td>';
                        html += '<td>' + v.card_total_amount + '</td>';
                        html += '<td>' + v.card_type + '</td>';
                        html += '<td>' + v.remark + '</td>';
                        html += '</tr>';
                    });
                    $('#add_tr').append(html);
                    //add by  dongleixin 显示发卡日志信息 start
                    if(o.data.apply.length != 0){
                        var applyHtml = "";
                        $('#apply').css('display', 'block');
                        $.each(o.data.apply,function(k,v){

                            applyHtml += '<tr>';
                            applyHtml += '<td style="text-align:center;">' + v.extend_9 + '</td>';
                            applyHtml += '<td style="text-align:center;">' + v.extend_10 + '</td>';
                            applyHtml += '<td style="text-align:center;">' + v.extend_2 + '</td>';
                            applyHtml += '<td style="text-align:center;">' + v.extend_7 + '</td>';
                            applyHtml += '<td style="text-align:center;">' + v.createTime + '</td>';
                            applyHtml += '<td style="text-align:center;">' + v.creator + '</td>';
                            applyHtml += '</tr>';
                        });
                        $('#add_str').append(applyHtml);
                    }
                    //add by  dongleixin 显示发卡日志信息 end
            }
        }
    });

    },

    del:function( apply_id ){
        cardApplyList.apply_id = apply_id;
        E.confirm('您确认要删除当前申领单吗？', 'cardApplyList.delExecute');
    },

    delExecute: function() {
        E.loadding.open('正在删除，请稍候...');
        E.ajax_post({
            url: '/invokingAjax-backend/company/cardApply.ajax?operFlg=100&act=del',
            data: {
                apply_id:cardApplyList.apply_id
            },
            call: 'cardApplyList.delResult'
        });
    },

    delResult: function( o ) {

        E.loadding.close();
        if (o.code == 200) {
            E.alert('删除成功', 2, 'cardApplyList.load');
        } else {
            E.alert(o.message);
        }

    },

    //审核确认
    audit:function( apply_id ){
        this.apply_id = apply_id;

        E.confirm('您确认审核编号为'+ apply_id +'的申领单吗?', "cardApplyList.auditExe");
    },

    //执行审核
    auditExe: function () {
        var args = new Array();
        args.url = "/invokingAjax-backend/company/cardApply.ajax?operFlg=6"
        args.data = {apply_id:cardApplyList.apply_id};
        args.call = 'cardApplyList.callback';
        E.ajax_post(args);
        E.popup.close();
    },

    //回调函数
    callback: function( obj ) {

        if( obj.code == 200 ){
            E.alert( obj.message , 2 , 'cardApplyList.load');
        }else{
            E.alert(obj.message);
        }

    },

    //申领单发卡
    tuck:{
        open:function(apply_id){
            E.open("/quanliadmin/app/company/cardApply.pscript?operFlg=3&apply_id="+apply_id, "" , {height: 500,width:880, top: 50, left: 250});
        }
    },

    //申领单发卡
    out:{
        invoice:function(apply_id){
            window.open("/quanliadmin/app/company/cardApply.pscript?operFlg=4&apply_id="+apply_id) ;
        }
    },

    //申领单回款
    returned:{
        money:function(apply_id){
            E.open("/quanliadmin/app/company/cardApply.pscript?operFlg=5&apply_id="+apply_id, "" , {height: 500,width:880, top: 50, left: 250});
        }
    },

    //重新加载表格
    load: function() {
        $("#flex").flexReload();
    },
    //申领单不合格通知销售员修改
    display: function(zt) {

        var html = "<form method=\"post\" id=\"messageForm\" name=\"messageForm\">";
        html += "<table>";
        html += "<tr>";
        html += "<td width=\"50\">内容：</td>";
        html += "<td width=\"*\">";
        html += "<textarea class='form-control' id=\"Remark\" name=\"Remark\" style=\"width:300px;height:100px;\"></textarea>";
        html += "</td>";
        html += "</tr>";
        html += "</tbody>";
        html += "</table>";
        html += "</form>";

        E.popup.open({
            title: "短信内容",
            content: html,
            btnName: "发送",
            btnCall: "cardApplyList.addInnerWord('"+zt+"');",
            css: 'width: 400px;'
        });

    },
    addInnerWord: function(zc) {
        //订单留言
        var remark = $('#Remark').val();
        if (!remark) {
            E.alert('请输入短信内容');
            return false;
        }
        E.ajax_get({
            url: "/invokingAjax-backend/card/cardApply.ajax?operFlg=14",
            data: {
                comment: remark,
                mobile: zc
            },
            call: "cardApplyList.result"
        });
    },
//返回结果
    result:function(o){
        if (o.code == 200) {
            E.alert(o.message, 2, "cardApplyList.load");
        } else {
            E.alert(o.message);
        }
        E.loadding.close();
    },
    load: function() {
        $("#flex").flexReload();
    }


};

$(window).ready(function() {


    $('#searchPanels').find('li').click(function() {

        var departmentID = $(this).attr('departmentID');
        if (departmentID > 0) {

            E.ajax_get({
                url: '/invokingAjax-backend/company/cardApply.ajax?operFlg=10',
                data: {
                    departmentID: departmentID
                },
                call: function( o ) {

                    if (o.code == 200) {

                        var html = '<option value="">请选择</option>';
                        if ( o.data ) {
                            $.each( o.data, function( k, v ) {
                                html += '<option value="' + v.userID + '">' + v.trueName + '</option>';
                            });
                        }
                        $('#userID').html(html);

                    } else {

                        E.alert( o.message);

                    }

                }
            });

        } else {
            var html = '<option value="">请选择</option>';
            $('#userID').html(html);
        }

    });

});

</script>

</body>
</html>